
angular.module('app')
    .controller('myChannelController', [ '$rootScope', '$scope', '$http', '$state','$timeout',
        function($rootScope, $scope, $http, $state, $timeout) {
            $scope.title = '我的频道管理';
            $scope.searchParams = { };
            $scope.loading = false;
            $scope.param={};
            $scope.search = function () {
                $scope.loading = true;
                $.ajax({
                    url : $scope.app.project_name+'/myChannel/read/list',
                    data: $scope.searchParams
                }).then(function(result) {
                    console.log(result);
                    $scope.loading = false;
                    if (result.httpCode == 200) {
                        $scope.pageInfo = result.data;

                    } else {
                        $scope.msg = result.msg;
                    }
                    $scope.$apply();
                });
            }

            $scope.searchRe = function () {
                $scope.loading = true;
                $scope.searchParams.pageNum = 1;
                $.ajax({
                    url : $scope.app.project_name+'/myChannel/read/list',
                    data: $scope.searchParams
                }).then(function(result) {

                    $scope.loading = false;
                    if (result.httpCode == 200) {
                        $scope.pageInfo = result.data;

                    } else {
                        $scope.msg = result.msg;
                    }
                    $scope.$apply();
                });
            }


            $scope.isSelected = function (id) {
                return $scope.selected.indexOf(id) >= 0;
            };


            $scope.search();

            $scope.clearSearch = function() {

                $scope.searchParams= { };
                $scope.search();
                $(".editSortBtn").show();
                $(".saveSortBtn").hide();
            }



            // 翻页
            $scope.pagination = function (pageNo) {
                $scope.searchParams.pageNum=pageNo;
                $scope.search();
            };


            $scope.businessLicenses = [];
            $scope.preview = function(businessLicense){
                if (businessLicense != null && businessLicense != '') {
                    $scope.businessLicenses = businessLicense.split('|');
                }
                $scope.firstApply = true;
            }

            // 删除用户
            $scope.enableOrdisabled=function (channelNo,enable) {
                $scope.alertModel({
                    text:'确定此操作？',
                    btnCancel:true,
                    resCode:"10000"
                }).then(function(){
                    $.ajax({
                        url : $scope.app.project_name+'/myChannel/enableOrdisabled',
                        data: {channelNo:channelNo,enable:enable}
                    }).then(function(result) {
                        $scope.loading = false;
                        $scope.alertModal({"content":"操作成功"});
                        if (result.httpCode != 200) {
                            $scope.alertModal(result.msg);
                        }
                        $scope.search();
                    });

                })

            }


        } ]);